<?php
function add_interface_to_groupdefault(){
	db_execute('Insert into plugin_nms_interfacegroup(interface_group_id,interface_id) select 1,interface_id from plugin_nms_interface');
}
function add_one_interface_to_groupdefault($id){
	db_execute('Insert into plugin_nms_interfacegroup(interface_group_id,interface_id) select 1,'.$id.' from plugin_nms_interface');
}
function add_groupdefault(){
	db_execute('INSERT INTO plugin_nms_groupname (group_name) VALUES ("Default Group"),("Group Host")');
}
function add_all_interface_into_table() {
	db_execute('insert  into plugin_nms_interface(host_id,snmp_index)
				select host_id,snmp_index
				from host_snmp_cache
				where field_value like "ethernetCsmacd%"
				order by host_id,snmp_index *1 ');
}
function add_host_interface_into_table($host_id) {
	db_execute('insert  into plugin_nms_interface(host_id,snmp_index)
				select host_id,snmp_index
				from host_snmp_cache
				where field_value like "ethernetCsmacd%" and host_id ="'.$host_id.'"
				order by host_id,snmp_index *1 ');
}
function add_interface_into_table($host_id,$snmp_index){
	db_execute('insert  into plugin_nms_interface(host_id,snmp_index)
								select host_id,snmp_index
								from host_snmp_cache
									where host_id="'.$host_id.'" and snmp_index ="'.$snmp_index.'"
									group by host_id,snmp_index *1');
}
function update_value_all_interface($host_id){
		db_execute('UPDATE plugin_nms_interface as a
 					SET interface_name = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifName"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						interface_alias = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifAlias"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						nms_status = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifOperStatus"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						status_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifOperStatus"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						alias_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifAlias"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						present = 1
 				 	Where a.host_id = "'.$host_id.'"');
}
function update_value_all_interface_1($host_id){
	db_execute('UPDATE plugin_nms_interface as a
 					SET interface_name = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifName"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						interface_alias = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifAlias"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						nms_status = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifOperStatus"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						status_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifOperStatus"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						alias_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifAlias"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index)
 				 	Where a.host_id = "'.$host_id.'"');
}
function update_value_interface($host_id,$snmp_index){
	db_execute('UPDATE plugin_nms_interface as a
 					SET interface_name = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifName"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						interface_alias = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifAlias"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index ),
 						nms_status = (SELECT field_value FROM host_snmp_cache as b
										Where b.field_name= "ifOperStatus"
 											and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						status_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifOperStatus"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						alias_oid = ( SELECT oid FROM host_snmp_cache as b
									Where b.field_name= "ifAlias"
 										and a.host_id =b.host_id and a.snmp_index =b.snmp_index),
 						present = 1
 				 	where host_id="'.$host_id.'" and snmp_index ="'.$snmp_index.'"');
}
function update_present_interface($host_id,$snmp_index){
	db_execute('Update plugin_nms_interface set present =0 where host_id="'.$host_id.'" and snmp_index ="'.$snmp_index.'"');
}
function add_all_log_into_table($user_id){
	db_execute('Insert into plugin_nms_log (interface_id,nms_status, nms_time,interface_group_id, user_active)
							select interface_id,nms_status,now(),1,"'.$user_id.'"
							from plugin_nms_interface');
}
function add_all_hostlog(){
	db_execute('Insert into plugin_nms_hostlog (host_id,host_status,host_time)
					select id,status,now()
					from host');
}
function add_log_into_table($user_id,$host_id,$snmp_index){
db_execute('Insert into plugin_nms_log (interface_id,nms_status, nms_time,interface_group_id, user_active)
							select interface_id,nms_status,now(),1,"'.$user_id.'"
							from plugin_nms_interface where host_id="'.$host_id.'" and snmp_index ="'.$snmp_index.'"');
}
function add_one_hostlog($id){
	db_execute('Insert into plugin_nms_hostlog (host_id,host_status,host_time)
					select id,status,now()
					from host where id = '.$id.'');
}
function addsoundevice($id){
	db_execute('UPDATE host SET warning = 1 WHERE id = '.$id.'');
}
function add_log_host_into_table($user_id,$host_id){
	db_execute('Insert into plugin_nms_log (interface_id,nms_status, nms_time,interface_group_id, user_active)
							select interface_id,nms_status,now(),1,"'.$user_id.'"
							from plugin_nms_interface where host_id="'.$host_id.'"');
}
function update_sound_setting($up,$down,$ddown){
	db_execute('Update plugin_nms_setting
	 				Set sound_up =0,
	 					 sound_down =0,
						 device_down =0');
	db_execute('Update plugin_nms_setting
	 				Set sound_up =1
	 				Where sound_id = "'.$up.'"');
	db_execute('Update plugin_nms_setting
	 				Set sound_down =1
	 				Where sound_id = "'.$down.'"');
	db_execute('Update plugin_nms_setting
	 				Set device_down =1
	 				Where sound_id = "'.$ddown.'"');
}
function delete_sound($id){
	db_execute('DELETE FROM plugin_nms_setting
 				WHERE sound_id = '.$id.'');
}
?>